package com.wanmait.spacesys.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieUtil {
		//添加cookie
		public static void addCookie(String name, String value, String path, int maxAge, HttpServletResponse response) {
			Cookie cookie=new Cookie(name,value);
			cookie.setPath(path);
			cookie.setMaxAge(maxAge);
			response.addCookie(cookie);
		}
		//获得cookie
		public static String getCookie(String name,HttpServletRequest request) {
			Cookie[] cookies=request.getCookies();
			String cookieValue="";
			for(Cookie c:cookies) {
				if(name.equals(c.getName())) {
					cookieValue=c.getValue();
				}
			}
			return cookieValue;
		}
		
		
	}

